package src

import (
	"log"

	"github.com/emersion/go-imap"
	id "github.com/emersion/go-imap-id"
	"github.com/emersion/go-imap/client"
)

type CustomCommand struct {
	CommandName string
	Args        []string
}

func (cmd *CustomCommand) Command() *imap.Command {
	return &imap.Command{
		Name:      cmd.CommandName,
		Arguments: []interface{}{cmd.Args[0], cmd.Args[1], cmd.Args[2], cmd.Args[3], cmd.Args[4], cmd.Args[5]},
	}
}

func Email() {
	log.Println("开始连接邮箱服务器......")

	c, err := client.DialTLS("imap.163.com:993", nil)

	if err != nil {
		log.Fatal(err)
	}
	idclient := id.NewClient(c)
	idclient.ID(
		id.ID{id.FieldName: "IMAPClient", id.FieldVersion: "1.0.0"},
	)
	log.Println("连接成功")

	defer c.Logout()

	if err := c.Login("zenghaifenghandsom@163.com", "QDunvLP8Vrnhn5hJ"); err != nil {
		log.Fatal(err)
	}
	log.Printf("登陆成功")

	log.Println("ID 命令执行成功")

	mbox, err := c.Select("INBOX", false)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Flag for INBOX:", mbox.Flags)

}
